// packageApply/pages/record/record.js
import { getCountRecord } from "../../../public/api/device.js"
import {
  throttle,
  formatTime
} from "../../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    maxDate: new Date().getTime(),
    minDate: '',
    chooseDate: '',
    date: "",
    recordList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.getDetail(options.uuid,options.date)
    let now = new Date()
    let chooseDate = formatTime(new Date()).slice(0,10).replace(/\//g, '-')
    now.setMonth(now.getMonth() - 11)
    this.setData({
      uuid: options.uuid,
      minDate: now.getTime(),
      chooseDate,
    })
    this.getDetail()
  },

  getDetail() {
    let data = {}
    data.uuid = this.data.uuid
    data.startTime = `${this.data.chooseDate} 00:00:00`
    data.endTime = `${this.data.chooseDate} 23:59:59`
    getCountRecord(data).then(res => {
      if(res.data.code === 1) {
        this.setData({recordList: res.data.data})
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },

  openPopup: throttle(function() {
    this.setData({show: true})
  }, 1000),

  doCancel() {
    this.setData({show: false})
  },

  chooseDate(e) {
    let chooseDate = formatTime(new Date(e.detail)).slice(0,10).replace(/\//g, '-')
    this.setData({
      show: false,
      chooseDate
    })
    this.getDetail()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})